package com.hospital.dictionary.utils;

import com.alibaba.fastjson.JSON;
import com.hospital.common.core.result.ErrorTip;
import com.hospital.common.core.result.SuccessTip;
import com.hospital.common.core.result.Tip;
import com.hospital.dictionary.module.entity.StaffDict;

import javax.servlet.http.HttpServletRequest;

public class KitUtil {

    public static StaffDict getEmployee(HttpServletRequest request){
        String userInfo = request.getAttribute("userInfo").toString();
        StaffDict operator = JSON.parseObject(userInfo, StaffDict.class);
        if(operator!=null){
            return  operator;
        }else{
            throw new RuntimeException("授权已失效,请重新登录");
        }
    }

    public static Tip setResult(boolean result, int code, String errMsg, Object data){
        if(result){
            return new SuccessTip(data);
        }else{
            return new ErrorTip(code,errMsg);
        }
    }
}
